<?php

if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
$f_showextra = true;
$ui = new UI();
include( "member/news.php" );
$conf = new Config();
if ($curruser['detailed_list'] == 0)
{
    $ui->showErrorPage("<p class=error>你没有权限查阅\会员下注清单！</p>", true);
    exit();
}
if ($conf->get("calcbet") == 1)
{
    $ui->showErrorPage("<p class=error>颁奖过帐中，请稍後再使用本功能！</p>", true);
    exit();
}
if ($curruser['acl'] == 255)
{
    $ipshowFlag = 1;
}
else if (intval($conf->Get("ipshow")))
{
    $ipshowFlag = 1;
}
else
{
    $ipshowFlag = 0;
}
echo title(L_BETLIST, "<a href='#' onclick='window.print()'>" . L_PRINT . "</a> | <a href='javascript:history.back()'>回上一页</a>");
echo "<br>";
echo "<table width=758 border=1 cellpadding=3 cellspacing=0>";
if (getvar("cmd") == "new")
{
    echo L_TENLIST . " <input type=button value=\"" . L_REFRESH . "\" onclick=location.reload()>";
}
echo "<tr class=td0 align=center>";
echo "<td nowrap>" . L_ID . " / " . L_TIME;
echo "<td nowrap>" . L_MEMBER . " / " . L_BACKWATER;
echo "<td nowrap>盘类 / 期数 / 开奖日期";
echo "<td nowrap>" . L_BETCONTENT;
echo "<td nowrap>赔率";
echo "<td nowrap>下注金额";
echo "<td nowrap>退水";
echo "<td nowrap>结果";
echo "<td nowrap>备注";
echo "<td nowrap>IP";
$user = new user();
$items = 0;
$itemsum = 0;
$itemresult = 0;
$bettype = 0;
$sql = "";
$sql2 = "";
$sql3 = "";
$sql8 = "";
$number = "";
$dist = "";
$dist2 = "";
$dist3 = "";
$dist8 = "";
$dt1 = getvar("dt1");
$dt2 = getvar("dt2");
$user_acl = 0;
$rs = getdb("select id from lotto where open>='" . $dt1 . "' and open<='" . $dt2 . "'");
$lottos = "";
$showUrlFlag = "class=\"span3da\"";
$showNoteTitle = "<span>※ 点选会员帐号，可查看<b>该会员</b>於<b>六合彩</b>所有的下注清单({$dt1}~{$dt2})。</span>";
$betRType = intval(getvar("betRType"));
switch ($betRType)
{
    case 1 :
        $rameSQLStr = "AND rame = 9 AND (b1 - a1) <= 0 ";
        $rameSQLStr2 = "AND rame = 9 AND (b2 - a2) <= 0 ";
        $rameSQLStr8 = "AND rame = 9 AND (r5 - back) <= 0 ";
        $whereRameSQLStr = "AND rame = 9 AND (b1 - a1) <= 0 ";
        $whereRameSQLStrAll = " AND rame = 9 AND (b1 - a1) <= 0 ";
        $rameTitleStr = " 选项:上缴";
        break;
    case 2 :
        $rameSQLStr = "AND rame = 9 AND (b1 - a1) > 0 ";
        $rameSQLStr2 = "AND rame = 9 AND (b2 - a2) > 0 ";
        $rameSQLStr8 = "AND rame = 9 AND (r5 - back) > 0 ";
        $whereRameSQLStr = "AND rame = 9 AND (b1 - a1) > 0 ";
        $whereRameSQLStrAll = " AND rame = 9 AND (b1 - a1) > 0 ";
        $rameTitleStr = " 选项:得分";
        break;
    default :
        $rameSQLStr = "";
        $rameSQLStr2 = "";
        $rameSQLStr8 = "";
        $whereRameSQLStr = "";
        $whereRameSQLStrAll = " AND a.rame IN (0,9) ";
        $rameTitleStr = " 选项:全部";
        break;
}
while (!$rs->eof)
{
    if ($lottos != "")
    {
        $lottos .= ",";
    }
    $lottos .= $rs->f['id'];
    $rs->movenext();
}
if ($lottos == "")
{
    $sql .= $dist . " 1=0";
    $dist = " and ";
    $sql2 .= $dist2 . " 1=0";
    $dist2 = " and ";
    $sql3 .= $dist3 . " 1=0";
    $dist3 = " and ";
    $sql8 .= $dist8 . " 1=0";
    $dist8 = " and ";
}
else
{
    $sql .= $dist . " lotto_id in (" . $lottos . ") {$rameSQLStr} ";
    $dist = " and ";
    $sql2 .= $dist2 . " lotto_id in (" . $lottos . ") {$rameSQLStr2} ";
    $dist2 = " and ";
    $sql3 .= $dist3 . " lotto_id in (" . $lottos . ") {$rameSQLStr2} ";
    $dist3 = " and ";
    $sql8 .= $dist8 . " lotto_id in (" . $lottos . ") {$rameSQLStr8}";
    $dist8 = " and ";
}
$user_acl = $curruser['acl'];
if (getvar("agent") != "" && getvar("agent") != 0 - 1)
{
    $info = get_user(getvar("agent"));
    if ($info)
    {
        $user_acl = $info['acl'];
        if (2 < $user_acl)
        {
            if ($curruser['acl'] != 255)
            {
                $sql2 .= $dist2 . " uperid" . $user_acl . "=" . getvar("agent") . " and user_id!=" . getvar("agent");
                $dist2 = " and ";
            }
            $users = GetUserList(getvar("agent"));
            if ($users == "")
            {
                $sql .= $dist . " 1=0";
                $dist = " and ";
            }
            else
            {
                $sql .= $dist . " user_id in (" . $users . ")";
                $dist = " and ";
            }
        }
        else
        {
            $sql .= $dist . " user_id=" . getvar("agent");
            $dist = " and ";
            $showUrlFlag = "";
            $showNoteTitle = "";
        }
        $sql3 .= $dist3 . " user_id=" . getvar("agent");
        $dist3 = " and ";
    }
    else
    {
        diemsg("<p class=error>错误的参数！</p>");
        exit();
    }
}
else if ($curruser['acl'] == 2)
{
    $users = GetUserList($curruser['id']);
    if ($users == "")
    {
        $sql .= $dist . " 1=0";
        $dist = " and ";
    }
    else
    {
        $sql .= $dist . " user_id in (" . $users . ")";
        $dist = " and ";
    }
    $sql3 .= $dist3 . " user_id=" . $curruser['id'];
    $dist3 = " and ";
}
else if ($curruser['acl'] != 255)
{
    $sql2 .= $dist2 . " uperid" . $curruser['acl'] . "=" . $curruser['id'] . " and user_id!=" . $curruser['id'];
    $dist2 = " and ";
    $users = GetUserList($curruser['id']);
    if ($users == "")
    {
        $sql .= $dist . " 1=0";
        $dist = " and ";
    }
    else
    {
        $sql .= $dist . " user_id in (" . $users . ")";
        $dist = " and ";
    }
    $sql3 .= $dist3 . " user_id=" . $curruser['id'];
    $dist3 = " and ";
}
$protmod = get_protmode($curruser['id']);
$maxdate = "";
if ($curruser['acl'] == 2)
{
    $rs = getdb("select open from lotto where open BETWEEN '2011-01-01' and '" . date("Y-m-d") . "' order by open desc LIMIT 20");
    while (!$rs->eof)
    {
        $maxdate = $rs->f['open'];
        $rs->movenext();
    }
    $sql .= $dist . " createtime >= " . strtotime($maxdate . " 00:00:00");
    $dist = " and ";
    $sql2 .= $dist2 . " createtime >= " . strtotime($maxdate . " 00:00:00");
    $dist2 = " and ";
    $sql3 .= $dist2 . " createtime >= " . strtotime($maxdate . " 00:00:00");
    $dist3 = " and ";
    $sql8 .= $dist8 . " createtime >= " . strtotime($maxdate . " 00:00:00");
    $dist8 = " and ";
}
if (isset($_GET['bettype']) && $_GET['bettype'] != "")
{
    $bettype = intval($_GET['bettype']);
    if ($bettype == 99)
    {
        $sql .= $dist . " bettype in (0,24)";
        $dist = " and ";
        $sql2 .= $dist2 . " bettype in (0,24)";
        $dist2 = " and ";
        $sql3 .= $dist3 . " bettype in (0,24)";
        $dist3 = " and ";
        $sql8 .= $dist8 . " bettype in (0,24)";
        $dist8 = " and ";
        $bettype = 0;
    }
    else if ($bettype == 88)
    {
        $sql .= $dist . " bettype in (25,26)";
        $dist = " and ";
        $sql2 .= $dist2 . " bettype in (25,26)";
        $dist2 = " and ";
        $sql3 .= $dist3 . " bettype in (25,26)";
        $dist3 = " and ";
        $sql8 .= $dist8 . " bettype in (25,26)";
        $dist8 = " and ";
        $bettype = 25;
    }
    else if ($bettype == 77)
    {
        $sql .= $dist . " bettype in (4,31)";
        $dist = " and ";
        $sql2 .= $dist2 . " bettype in (4,31)";
        $dist2 = " and ";
        $sql3 .= $dist3 . " bettype in (4,31)";
        $dist3 = " and ";
        $sql8 .= $dist8 . " bettype in (4,31)";
        $dist8 = " and ";
        $bettype = 4;
    }
    else if ($bettype == 1006)
    {
        $sql .= $dist . " bettype in (21, 37)";
        $dist = " and ";
        $sql2 .= $dist2 . " bettype in (21, 37)";
        $dist2 = " and ";
        $sql3 .= $dist3 . " bettype in (21, 37)";
        $dist3 = " and ";
        $sql8 .= $dist8 . " bettype in (21, 37)";
        $dist8 = " and ";
        $bettype = 0;
    }
    else if ($bettype == 1007)
    {
        $sql .= $dist . " bettype in (22, 38)";
        $dist = " and ";
        $sql2 .= $dist2 . " bettype in (22, 38)";
        $dist2 = " and ";
        $sql3 .= $dist3 . " bettype in (22, 38)";
        $dist3 = " and ";
        $sql8 .= $dist8 . " bettype in (22, 38)";
        $dist8 = " and ";
        $bettype = 0;
    }
    else
    {
        $sql .= $dist . " bettype=" . $bettype;
        $dist = " and ";
        $sql2 .= $dist2 . " bettype=" . $bettype;
        $dist2 = " and ";
        $sql3 .= $dist3 . " bettype=" . $bettype;
        $dist3 = " and ";
        $sql8 .= $dist8 . " bettype=" . $bettype;
        $dist8 = " and ";
    }
}
$order = 0;
if (( $bettype == 25 || $bettype == 26 ) && isset($_GET['order']) && $_GET['order'] != "")
{
    $order = intval($_GET['order']);
}
if (isset($_GET['numbers']) && $_GET['numbers'] != "")
{
    $number = $_GET['numbers'];
    if ($bettype == 19)
    {
        $sql .= $dist . " numbers like '" . $number . "%'";
        $dist = " and ";
    }
    else if ($bettype == 27 || $bettype == 36)
    {
        if (!strpos($number, "|"))
        {
            $sql .= $dist . " numbers like '" . $number . "%'";
            $dist = " and ";
        }
        else
        {
            $sql .= $dist . " numbers='" . $number . "'";
            $dist = " and ";
        }
    }
    else if (( $bettype == 25 || $bettype == 26 ) && 0 < $order)
    {
        $sql .= $dist . " numbers='" . $order . " " . $number . "'";
        $dist = " and ";
    }
    else
    {
        $sql .= $dist . " numbers='" . $number . "'";
        $dist = " and ";
    }
}
$sql0 = "select sum(amount),sum(a1),sum(b1),count(id) from bet" . ( $sql != "" ? " where " . $sql : "" ) . " order by createtime desc";
$sql = "select * from bet" . ( $sql != "" ? " where " . $sql : "" ) . " order by createtime desc, bettype, numbers";
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
$pagesize = 0;
$tot_amount = 0;
$tot_a1 = 0;
$tot_b1 = 0;
$tot_count = 0;
if ($page == 0 - 1)
{
    $page = 1;
    $pagesize = 40;
}
else
{
    $rs0 = getdb($sql0);
    $tot_amount = $rs0->f[0];
    $tot_a1 = $rs0->f[1];
    $tot_b1 = $rs0->f[2];
    $tot_count = $rs0->f[3];
    $rs0->close();
    if ($page == 0)
    {
        $page = 1;
    }
    $pagesize = 20;
}
$rs = getdb($sql, $page, $pagesize);
$sum2 = 0;
$sum3 = 0;
$sum4 = 0;
$bingo = 0;
$total = 0;
$totalback = 0;
$movenext = !$rs->eof;
while ($movenext)
{
    $info = get_user($rs->f['user_id']);
    if ($info)
    {
        ++$items;
        echo "<tr align=right class=td2 onmouseover=msover() onmouseout=msout() valign=top>";
        echo "<td nowrap><font color=#217952>" . $rs->f['id'] . "</font> &nbsp; " . date("m-d H:i:s", $rs->f['createtime']);
        echo "<td nowrap><span {$showUrlFlag} onclick=\"javascript:paper(" . $info['id'] . ");\">" . $info['account'] . "</span> &nbsp; <font color=#217952>" . ( 100 - $rs->f['back1'] ) . "</font>";
        echo "<td nowrap>";
        echo $g_disk_name[$rs->f['disk']] . " / ";
        $lotto = get_lotto($rs->f['lotto_id']);
        echo d3($lotto->data['round']) . " 期 <font color=#217952>" . $lotto->data['open'] . "</font>";
        echo "<td nowrap>";
        echo GetBetContent($rs->f['bettype'], $rs->f['numbers'], $rs->f['amount']);
        echo "<td nowrap>" . show_rate($rs->f['bettype'], $rs->f['rate']) . "</td>";
        $tmp1 = $rs->f['amount'];
        echo "<td nowrap>" . $tmp1;
        echo "<td nowrap>" . $rs->f['a1'];
        $tmp2 = $rs->f['b1'];
        echo "<td nowrap>" . say_numbercolor($tmp2);
        $reme = "";
        if ($rs->f['rame'] == 1)
        {
            $reme = "逾时";
        }
        if ($rs->f['rame'] == 2)
        {
            $reme = "取消";
        }
        if ($rs->f['rame'] == 3)
        {
            $reme = "异常";
        }
        if ($rs->f['rame'] == 4)
        {
            $reme = "特连";
        }
        if (chkBet_peace($rs->f))
        {
            $reme .= " <font class='betpeace'>和局</font>";
        }
        if ($curruser['acl'] == 255)
        {
            $reme .= floatval($rs->f['rate5']) ? "<font class=\"c5\">[" . floatval($rs->f['rate5']) . "]</font>" : "";
        }
        echo "<td nowrap><font color='red'>" . $reme . "</font>";
        echo "<td nowrap>" . ( $ipshowFlag ? $rs->f['ip'] : "" );
        $tmp3 = $rs->f['a1'] + $rs->f['b1'];
        if ($reme == "")
        {
            $total += $tmp3;
            $totalback += $rs->f['a1'];
            $itemsum += $tmp1;
            $itemresult += $tmp2;
        }
    }
    $rs->movenext();
    $movenext = !$rs->eof;
}
if (0 < $pagesize)
{
    if (15 < $tot_count)
    {
        echo "<tr class=td1><td colspan=4 align=right><b>小计 " . $items . " 笔</b>";
        echo "<td nowrap align=right><b></b>";
        echo "<td nowrap align=right><b>" . $itemsum . "</b>";
        echo "<td nowrap align=right><b>" . sprintf("%.2f", $totalback) . "</b>";
        echo "<td nowrap align=right><b>" . say_numbercolor($itemresult) . "</b>";
        echo "<td nowrap align=right>";
    }
    echo "<tr class=td3><td colspan=4 align=right><b>合计 " . $tot_count . " 笔</b>";
    echo "<td nowrap align=right><b></b>";
    echo "<td nowrap align=right><b>" . $tot_amount . "</b>";
    echo "<td nowrap align=right><b>" . sprintf("%.2f", $tot_a1) . "</b>";
    echo "<td nowrap align=right><b>" . say_numbercolor($tot_b1) . "</b>";
    echo "<td nowrap align=right>";
    echo "<tr><td class=td0 colspan=10>" . $rs->pagelink() . "</td></tr>";
}
else
{
    echo "<tr class=td1><td colspan=4 align=right><b>小计 " . $items . " 笔</b>";
    echo "<td nowrap align=right><b></b>";
    echo "<td nowrap align=right><b>" . $itemsum . "</b>";
    echo "<td nowrap align=right><b>" . sprintf("%.2f", $totalback) . "</b>";
    echo "<td nowrap align=right><b>" . say_numbercolor($itemresult) . "</b>";
    echo "<td nowrap align=right>";
}
echo "</table>";
echo $showNoteTitle;
echo "<form name=f method=get action='op.php'>\r\n<input type=hidden name=op value='agent'>\r\n<input type=hidden name=fp value='betlist'>\r\n<input type=hidden name=agent>\r\n<input type=hidden name=dt1 value='{$dt1}'>\r\n<input type=hidden name=dt2 value='{$dt2}'>    \r\n<input type=hidden name=cmd value='" . getvar("cmd") . "'>\r\n<input type=hidden name=gametype value='0'>\r\n<input type=hidden name=betRType value='{$betRType}'>\r\n</form>\r\n<style type=\"text/css\">\r\n.span3da{\r\ncursor: pointer;\r\ncolor:blue;\r\ntext-decoration:underline;\r\n}\r\n</style>\r\n<script>\r\nfunction paper(subid)\r\n{";
if ($showUrlFlag == "")
{
    echo " return false;";
}
else
{
    echo " f.agent.value = subid; f.submit();";
}
echo "\r\n}\r\n</script>";
if (1 < $user_acl)
{
    if ($items && 2 < $curruser['acl'] && ( $protmod == 1 || $curruser['acl'] == 255 ))
    {
        $sqlx = $sql2;
        $sql2 = " bet2" . ( $sql2 != "" ? " where " . $sql2 : "" );
        if ($number != "")
        {
            $sql2 .= $dist2;
            if ($bettype == 19)
            {
                $sqlx .= $dist2 . " numbers like '" . $number . "%'";
            }
            else if ($bettype == 27 || $bettype == 36)
            {
                if (!strpos($number, "|"))
                {
                    $sqlx .= $dist2 . " numbers like '" . $number . "%'";
                }
                else
                {
                    $sqlx .= $dist2 . " numbers='" . $number . "'";
                }
            }
            else if (( $bettype == 25 || $bettype == 26 ) && 0 < $order)
            {
                $sqlx .= $dist2 . " numbers='" . $order . " " . $number . "'";
            }
            else
            {
                $sqlx .= $dist2 . " numbers='" . $number . "'";
            }
        }
        $sqlx = $sqlx != "" ? " where " . $sqlx : "";
        $rst = getdb("select * from bet2" . $sqlx);
        if (!$rst->eof)
        {
            echo "<br>";
            echo title("下线 <a href='?op=agent&fp=bet2list&c=" . $sql2 . "&o=" . $order . "&n=" . $number . "&t=" . $bettype . "&betRType={$betRType}'>走飞清单</a>");
        }
    }
    if ($items)
    {
        if ($curruser['acl'] == 255)
        {
            $sqlx = $sql8;
            $sql8 = " bet8" . ( $sql8 != "" ? " where " . $sql8 : "" );
            if ($number != "")
            {
                $sql8 .= $dist8;
                if ($bettype == 19)
                {
                    $sqlx .= $dist8 . " numbers like '" . $number . "%'";
                }
                else if ($bettype == 27 || $bettype == 36)
                {
                    if (!strpos($number, "|"))
                    {
                        $sqlx .= $dist8 . " numbers like '" . $number . "%'";
                    }
                    else
                    {
                        $sqlx .= $dist8 . " numbers='" . $number . "'";
                    }
                }
                else if (( $bettype == 25 || $bettype == 26 ) && 0 < $order)
                {
                    $sqlx .= $dist8 . " numbers='" . $order . " " . $number . "'";
                }
                else
                {
                    $sqlx .= $dist8 . " numbers='" . $number . "'";
                }
            }
            $sqlx = $sqlx != "" ? " where " . $sqlx : "";
            $rst = getdb("select * from bet8 " . $sqlx);
            if (!$rst->eof)
            {
                echo "<br>";
                echo title("公司 <a href='?op=agent&fp=bet8list&c=" . $sql8 . "&o=" . $order . "&n=" . $number . "&t=" . $bettype . "&betRType={$betRType}'>走飞清单</a>");
            }
        }
        else
        {
            $sqlx = $sql3;
            $sql3 = " bet2" . ( $sql3 != "" ? " where " . $sql3 : "" );
            if ($number != "")
            {
                $sql3 .= $dist3;
                if ($bettype == 19 || $bettype == 27 || $bettype == 36)
                {
                    $sqlx .= $dist3 . " numbers like '" . $number . "%'";
                }
                else if (( $bettype == 25 || $bettype == 26 ) && 0 < $order)
                {
                    $sqlx .= $dist3 . " numbers='" . $order . " " . $number . "'";
                }
                else
                {
                    $sqlx .= $dist3 . " numbers='" . $number . "'";
                }
            }
            $sqlx = $sqlx != "" ? " where " . $sqlx : "";
            $rst = getdb("select * from bet2 " . $sqlx);
            if (!$rst->eof)
            {
                echo "<br>";
                echo title("本身 <a href='?op=agent&fp=bet3list&c=" . $sql3 . "&o=" . $order . "&n=" . $number . "&t=" . $bettype . "&betRType={$betRType}'>走飞清单</a>");
            }
        }
    }
}
$ui->footer();
?>